/**
 * created  on 21/09/2017.
 */

// window.addEventListener("offline",function () {
//     alert("你的电脑已离线");
// });
// window.addEventListener("online",function () {
//     alert("你的电脑已恢复网络");
// });
function Params() {
    this.content = "json";
}

$.ajaxSetup({
    complete: function (XHR, TS) {

        if (XHR.status === 400) {
            alert("没有找到相应资源,将刷新当前网页!");
            window.location.reload();
        } else if (XHR.status === 403) {
            alert("您没有访问权限! 将刷新当前网页!");
            location.reload();
        } else if(XHR.status === 302){
            location.reload();
        }else if(XHR.status === 500){

            alert("服务器错误:" + XHR.responseText);
        } else if (XHR.getResponseHeader("xx-accessControl") === "ACCESS_DENIED") {
            location.assign(XHR.getResponseHeader("xx-forwardUrl"))
        } else if (XHR.getResponseHeader("xx-accessControl") === "UNAUTHORIZED") {
            alert("您的登录已失效! 请重新登录!");
            location.reload();
        }else if(XHR.getResponseHeader("xx-accessControl") === "INVALID_CSRF_TOKEN"){
            alert("非法访问,没有 CSRF Token");
            location.assign(XHR.getResponseHeader("xx-forwardUrl"))
        }
    }
    /*,beforeSend:function (XHR) {
        if(JQUERY_SEND_CSRF_HEAD){
            let header,token;
            header = document.querySelector("meta[name='_csrf_header']").getAttribute("content");
            token = document.querySelector("meta[name='_csrf']").getAttribute("content");
            XHR.setRequestHeader(header, token);
        }
    }*/
})
;